//
//  DebugFrontBaseViewController.m
//  YK_DebugManager
//
//  Created by edward on 2021/1/14.
//

#import "DebugFrontBaseViewController.h"

@interface DebugFrontBaseViewController ()
///关闭按钮
@property(nonatomic,strong,readwrite) UIButton *closeButton;
///功能按钮
@property(nonatomic,strong,readwrite) UIButton *funcButton;
///safeView
@property(nonatomic,strong,readwrite) UIView *safeView;
///
@property(nonatomic,strong) UILabel *titleLabel;
@end

@implementation DebugFrontBaseViewController

- (instancetype)initWithDissMissBlock:(void(^)(void))dissMissBlock
{
    self = [super init];
    if (self) {
        self.dissMissBlock = dissMissBlock;
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor.grayColor colorWithAlphaComponent:0.3];
    [self setEdgesForExtendedLayout:UIRectEdgeNone];
    
    [self.view addSubview:self.funcButton];
    [self.view addSubview:self.closeButton];
    [self.view addSubview:self.titleLabel];
    [self.view addSubview:self.safeView];
}

- (void)addCustomView:(UIView *)customView
{
    [self.safeView addSubview:customView];
}


- (UIButton *)closeButton
{
    if (!_closeButton) {
        UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        closeButton.frame = CGRectMake(self.view.bounds.size.width - 100, 0, 30, 30);
        [closeButton setTitle:@"×" forState:UIControlStateNormal];
        closeButton.layer.borderColor = UIColor.whiteColor.CGColor;
        closeButton.layer.borderWidth = 1;
        closeButton.userInteractionEnabled = YES;
        [closeButton addTarget:self action:@selector(dissMiss:) forControlEvents:UIControlEventTouchUpInside];
        _closeButton = closeButton;
    }
    return _closeButton;
}
- (UIButton *)funcButton
{
    if (!_funcButton) {
        UIButton *funcButton = [UIButton buttonWithType:UIButtonTypeCustom];
        funcButton.frame = CGRectMake(70, 0, 30, 30);
        [funcButton setTitle:@"c" forState:UIControlStateNormal];
        funcButton.layer.borderColor = UIColor.whiteColor.CGColor;
        funcButton.layer.borderWidth = 1;
        funcButton.userInteractionEnabled = YES;
        [funcButton addTarget:self action:@selector(funcClick:) forControlEvents:UIControlEventTouchUpInside];
        _funcButton = funcButton;
    }
    return _funcButton;
}

- (UIView *)safeView
{
    if (!_safeView) {
        _safeView = [[UIView alloc] initWithFrame:CGRectMake(0, 30, self.view.bounds.size.width, self.view.bounds.size.height - 30)];
        _safeView.backgroundColor = UIColor.clearColor;
    }
    return _safeView;
}

- (UILabel *)titleLabel
{
    if(!_titleLabel)
    {
        _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake((self.view.bounds.size.width - 100)/2, 0, 100, 30)];
        _titleLabel.text = self.title;
        _titleLabel.textColor = [UIColor.blackColor colorWithAlphaComponent:0.7];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont systemFontOfSize:15 weight:UIFontWeightBold];
    }
    return _titleLabel;
}

- (void)dissMiss:(UIButton *)sender
{
    if(self.dissMissBlock)
    {
        self.dissMissBlock();
    }
    [self dissMiss];
}

- (void)dissMiss
{
    
}

- (void)setTitle:(NSString *)title
{
    [super setTitle:title];
}

- (void)funcClick:(UIButton *)sender
{
    [self funcClick];
}

- (void)funcClick
{
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
